package day2003;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class fwq {//服务器
    public static void main(String[] args) throws IOException {
        //启动服务器
        ServerSocket a = new ServerSocket(8000);
        System.out.println("服务器已经启动");

        //服务器接收客户端发来的信息
        Socket b = a.accept();
        System.out.println("来了一个请求");

        //接受客户端的数据
        InputStream c=b.getInputStream();
        char[] w =  new char[5];
        for (int i =0;i<5;i++){
            w[i]= (char) c.read();
        }
        System.out.println(new String(w));


        //给客户端发送数据
        OutputStream zz = b.getOutputStream();
        zz.write(new String(w).getBytes());
        zz.flush();
    }
}
